package com.dces.jx.billtest.imgCurrManage.service;
import com.xdo.domain.PageParam;
import com.dces.jx.billtest.dto.imgCurrManage.*;
import com.xdo.common.token.UserInfoToken;
import com.xdo.domain.ResultObject;
import com.xdo.common.base.service.BaseService;
import com.dces.jx.billtest.imgCurrManage.dao.EmsCusImgCurMapper;
import com.dces.jx.billtest.imgCurrManage.mapper.EmsCusImgCurDtoMapper;
import com.dces.jx.billtest.imgCurrManage.model.EmsCusImgCur;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jdk.nashorn.internal.runtime.options.Option;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.common.Mapper;
import javax.annotation.Resource;
import java.beans.Transient;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
/**
 * generated by Generate 神码
 * Service;
 *
 * @author xdoV2.0
 * @date: 2021-9-16
 */
@Service
public class EmsCusImgCurService extends BaseService<EmsCusImgCur> {
    @Resource
    private EmsCusImgCurMapper emsCusImgCurMapper;
    @Resource
    private EmsCusImgCurDtoMapper emsCusImgCurDtoMapper;
    @Override
    public Mapper<EmsCusImgCur> getMapper() {
        return emsCusImgCurMapper;
    }
    /**
     * 获取分页信息
     *
     * @author zuzhu
     * @param emsCusImgCurParam
     * @param pageParam
     * @return
     */
    public ResultObject<List<EmsCusImgCurDto>> getListPaged(EmsCusImgCurParam emsCusImgCurParam, PageParam pageParam) {
        // 启用分页查询
        EmsCusImgCur emsCusImgCur = emsCusImgCurDtoMapper.toPo(emsCusImgCurParam);
        Page<EmsCusImgCur> page = PageHelper.startPage(pageParam.getPage(), pageParam.getLimit(), pageParam.getSortOrderContent())
                .doSelectPage(() -> emsCusImgCurMapper.getList(emsCusImgCur));
        List<EmsCusImgCurDto> emsCusImgCurDtos = page.getResult().stream().map(head -> {
            EmsCusImgCurDto dto = emsCusImgCurDtoMapper.toDto(head);
            return dto;
        }).collect(Collectors.toList());
		ResultObject<List<EmsCusImgCurDto>> paged = ResultObject.createInstance(emsCusImgCurDtos, (int) page.getTotal(), page.getPageNum());
        return paged;
    }
    /**
     * 功能描述:查询所有数据
     *
     * @param exportParam
     * @param userInfo
     * @return
     */
    public List<EmsCusImgCurDto> selectAll(EmsCusImgCurParam exportParam, UserInfoToken userInfo) {
        EmsCusImgCur emsCusImgCur = emsCusImgCurDtoMapper.toPo(exportParam);
        // emsCusImgCur.setTradeCode(userInfo.getCompany());
        List<EmsCusImgCurDto> emsCusImgCurDtos = new ArrayList<>();
        List<EmsCusImgCur> emsCusImgCurs = emsCusImgCurMapper.getList(emsCusImgCur);
        if (CollectionUtils.isNotEmpty(emsCusImgCurs)) {
            emsCusImgCurDtos = emsCusImgCurs.stream().map(head -> {
                EmsCusImgCurDto dto = emsCusImgCurDtoMapper.toDto(head);
                return dto;
            }).collect(Collectors.toList());
        }
        return emsCusImgCurDtos;
    }
}
